#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys

a = ((1,2,3,4,5,6,19), \
(7,8,9,10,11,12,20), \
(13,14,15,16,17,18,21), \
(22,23,24,25,26,26,27), \
(1,2,3,4,5,6,7))

m = len(a)
n = len(a[0])

block_size = 2

blocks_m = m / block_size
end_m = blocks_m
if block_size*blocks_m < m:
   blocks_m += 1


blocks_n = n / block_size
end_n = blocks_n
if block_size*blocks_n < n:
   blocks_n += 1


def varre_bloco(bx, by, bw, bh):

   if bx + bw >= n:
      bw = n - bx

   if by + bh >= m:
      bh = m - by

   if bw <= 0 or bh <= 0:
      return

   for y in range(by, by+bh):
      linha = []
      for x in range(bx, bx+bw):
         linha.append( a[y][x] )
      #print linha

   #print

#encode
for y in range( m ):
	linha = []
	for x in range ( n ):
		linha.append( a[m - y - 1][n - x - 1] )
	print linha
print

#print str(blocks_m) + "x" + str(blocks_n)
#for y in range(blocks_m):
#   for x in range(blocks_n):
      #varre_bloco( x*block_size, y*block_size, block_size, block_size )
